//楼层定位
var timer = null;
var floorScroll = function(e, targetElement) {
	var event = e || window.e;
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	var height = $(targetElement).offset().top - $("header").height() - scrollTop;
	if($(targetElement).offset().top < $("header").height()) {
		height = -scrollTop;
	}
//	if($(targetElement).offset().top > $("div.contain").innerHeight() - $(window).height()) {
//		height = $("div.contain").innerHeight() - $(window).height() - scrollTop;
//	}
	height = Math.floor(height);
	var roll = height > 0 ? Math.floor(height / 10) : Math.ceil(height / 10);
	scrollTop += roll;
	document.documentElement.scrollTop = scrollTop;
	document.body.scrollTop = scrollTop;
	if(Math.abs(roll) == 0) {
		clearInterval(timer);
		if($(targetElement).offset().top == 0) {
			document.documentElement.scrollTop = 0;
			document.body.scrollTop = 0;
		}
	}
}
//浮动导航
var scrollBar = function(){
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	if(scrollTop>0){
		$("header").addClass("scroll");
		$("div.toTop").fadeIn();
	}else{
		$("header").removeClass("scroll");
		$("div.toTop").fadeOut();
	}
}
var floorPosition = function(e, targetElement) {
	var event = e || window.e;
	clearInterval(timer);
	timer = setInterval(function() {
		floorScroll(event, targetElement);
	}, 30)
}
var mouseScroll = function(){
	clearInterval(timer);
}
var loading = function(e){
			var n = 0.3;
			var deviceWidth = $(window).width();
			switch(true){
				case deviceWidth<=1280:n = 0.2;
				break;
				case deviceWidth<=1648&&deviceWidth>1280:n = 0.3;
				break;
				case deviceWidth<3072&&deviceWidth>1648:n = 0.4;
				break;
				case deviceWidth>=3072&&deviceWidth<4096:n = 0.6;
				break;
				case deviceWidth>=4096:n = 0.8;
				break;
			}
			$("meta[name='viewport']").attr("content","width=device-width,initial-scale="+n+",user-scalable=no")
			
			
		}
$(function() {
	loading();
	$(".case-list-title>li").click(function() {
		$(".case-content").children("div").hide();
		//					点击当前高亮
		$(".case-list-title>li").children("a").css("color", "#717171");
		$(this).children("a").css("color", "#007EFF")
		var i = $(this).index();
		//					点击当前显示
		$(".case-content").children("div").eq(i).fadeIn();
	})
	$(".case-content-right").hover(function() {
		$(this).css("background", "url(images/right_bg.png) 0 0 no-repeat");
	}, function() {
		$(this).css("background", "url(images/right_bg2.png) 0 0 no-repeat");
	})
	$(".case-content>span").hover(function() {
		$(".case-content-right").css("background", "url(images/right_bg.png) 0 0 no-repeat");
	}, function() {
		$(".case-content-right").css("background", "url(images/right_bg2.png) 0 0 no-repeat");
	})
	$(".case-content>span").click(function() {
		var lis = $(".case-content-list");
		var i;
		//					获取正在显示的索引
		lis.each(function() {
			if($(this).is(':visible')) {
				i = $(this).index();
				$(this).hide();
			}
		})
		i++;
		if(i == 6) {
			i = 0;
		}
		//					下一个显示
		lis.eq(i).fadeIn();
		//					下一个高亮
		$(".case-list-title>li").children("a").css("color", "#717171");
		$(".case-list-title>li").eq(i).children("a").css("color", "#007EFF");
	})
})

//视频播放
var videoPlay = function(){
	$("div.video").fadeIn();
	$("video").attr("src","../video/vrmaker_.mp4");
	$("#player")[0].play();
	$("span.pause").removeClass("glyphicon glyphicon-play").addClass("glyphicon glyphicon-pause");
	$("#video").click(function(){
		if($("#player")[0].paused == false){
			$("#player")[0].pause();
			$("span.pause").removeClass("glyphicon glyphicon-pause").addClass("glyphicon glyphicon-play");
		}else{
			$("#player")[0].play();
			$("span.pause").removeClass("glyphicon glyphicon-play").addClass("glyphicon glyphicon-pause")
		}
		
	});
}
//视频关闭
var closePlayer = function(){
	$("#player")[0].pause();
	$("div.video").fadeOut("300",function(){
		$("#player")[0].load();
	});
	$("#video").off("click");
}
//切换tab
var selectApplication = function(){
	scrollBar();
	$("ul.applicationAreaList li").click(function(){
//		$("ul.applicationAreaList li").stop().animate({"width":"200px"});
//		$(this).stop().animate({"width":"400px"});
//		
		$("ul.applicationIcon li").removeClass();
		$("ul.applicationIcon li").eq($(this).index()).addClass("active");
		$("ul.applicationAreaList li").removeClass();
		for(var i = 0 ;i < $("ul.applicationAreaList li").length;i++){
			var bgImg = $("ul.applicationAreaList li").eq(i).css("background-image");
			$("ul.applicationAreaList li").eq(i).removeClass("active").css("background-image",bgImg.replace(/gif/, "png"));
		}
		$(this).addClass("active").css("background-image",$(this).css("background-image").replace(/png/, "gif"));
	});
	$("ul.applicationIcon li").click(function(){
		$("ul.applicationIcon li").removeClass();
		$(this).addClass("active");
		$("ul.applicationAreaList li").removeClass();
		$("ul.applicationAreaList li").eq($(this).index()).addClass("active");
	});
	$("div.teamLeft>div").hover(function(){
		$("ul.teamMember li").removeClass("active");
		$("ul.teamMember li").eq($(this).index()).addClass("active");
		$("div.teamLeft>div").removeClass("active");
		$("div.teamLeft>div").eq($(this).index()).addClass("active");
	});
}



$(document).keydown(function(e){
	if(e.which == 27){
		closePlayer();
	}
	
});



document.addEventListener("mousewheel",mouseScroll,false);
document.addEventListener("DOMMouseScroll",mouseScroll,false);
document.addEventListener("mousedown",mouseScroll,false);
window.addEventListener("load",selectApplication,false);
//window.addEventListener("load",loading,false);
window.addEventListener("scroll",scrollBar,false);